package com.yf.exam.modules.trainingarchives.trainingassessmentreport.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.base.Preconditions;
import com.yf.exam.common.entity.Result;
import com.yf.exam.core.api.dto.BaseIdReqDTO;
import com.yf.exam.core.exception.ServiceException;
import com.yf.exam.modules.trainingarchives.organization.vo.OrganizationVO;
import com.yf.exam.modules.trainingarchives.studentassess.dto.StudentAssessDTO;
import com.yf.exam.modules.trainingarchives.studentassess.entity.StudentAssess;
import com.yf.exam.modules.trainingarchives.studentassess.vo.StudentAssessVO;
import com.yf.exam.modules.trainingarchives.trainingassessmentreport.dto.TrainingAssessmentReportDTO;
import com.yf.exam.modules.trainingarchives.trainingassessmentreport.entity.TrainingAssessmentReport;
import com.yf.exam.modules.trainingarchives.trainingassessmentreport.service.ITrainingAssessmentReportService;
import com.yf.exam.modules.trainingarchives.trainingassessmentreport.vo.TrainingAssessmentReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 综合考评报告表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-12-29
 */
@Api(tags={"综合考评报告表"})
@RestController
@RequestMapping("/training-assessment-report")
public class TrainingAssessmentReportController {

    @Resource
    private ITrainingAssessmentReportService iTrainingAssessmentReportService;

    @ApiOperation(value = "添加OR更新")
    @PostMapping(value = "/save")
    public Result save(@Valid @RequestBody TrainingAssessmentReportDTO reqDTO) {
        try {
            //复制参数
            iTrainingAssessmentReportService.add(reqDTO);
            return Result.ok();
        }catch (ServiceException e){
            return Result.faild(e);
        }
    }

    @ApiOperation(value = "查询详情")
    @PostMapping (value = "/get")
    public Result<OrganizationVO> get(@RequestBody BaseIdReqDTO reqDTO) {
        Preconditions.checkArgument(!StringUtils.isBlank(reqDTO.getId()), "培训班id不能为空!");
        TrainingAssessmentReport trainingAssessmentReport = iTrainingAssessmentReportService.getOne(
                Wrappers.<TrainingAssessmentReport>lambdaQuery().eq(TrainingAssessmentReport::getTrainingClassInfoId, reqDTO.getId())
        );
        TrainingAssessmentReportVO vo = new TrainingAssessmentReportVO();
        if (trainingAssessmentReport != null) {
            BeanUtils.copyProperties(trainingAssessmentReport,vo);
        }
        return Result.ok(vo);
    }


}
